﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace BGCOP.CAVTOP.COMMON
{
    public class LogCls
    {
        private string _eventoLog;
        public string Evento
        {
            get { return _eventoLog; }
            set { _eventoLog = value; }
        }
        /// <summary>
        /// propiedad para guardar la ruta del archivo
        /// </summary>
        /// <remarks></remarks>
        private string _fpath;
        public string FilePath
        {
            get { return _fpath; }
            set { _fpath = value; }
        }

        /// <summary>
        /// Agrega un evento al archivo de log
        /// </summary>
        /// <remarks></remarks>
        public void AddEvent()
        {
            int i = _fpath.IndexOf(".", System.StringComparison.Ordinal);
            string ftemp = _fpath.Insert(i, DateTime.Now.Day.ToString("0#") + DateTime.Now.Month.ToString("0#") + DateTime.Now.Year.ToString(CultureInfo.InvariantCulture));
            

            try
            {
                System.IO.StreamWriter sw = new StreamWriter(ftemp, true);
                // Add the first line from the file.
                sw.WriteLine("[" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + "] " + _eventoLog);
                sw.Close();
            }
            catch (Exception ex)
            {
                //Interaction.MsgBox(Err().Description);
            }

            
        }

    }
}
